intLoop = 1 Do Until intLoop = 10 Print intLoop
intLoop = intLoop + 1 Loop End Sub
Loop Until
The Loop Until loop checks the condition at the end of the loop instead of the beginning of the loop, just like Loop While. The statements inside the loop will always be performed at least once. Heres the syntax:
Do
<Statement Block>
Loop Until <Cond>
The following example is from the Loop Until command button.
Private Sub cmdLoopUntil_Click ()
Dim intLoop As Integer
Cls
intLoop = 1
Do
Print intLoop
intLoop = intLoop + 1
Loop Until intLoop = 10 End Sub
For . . . Next
For...Next loops are generally used when you know the exact number of iterations that need to be performed. Youll always use a counter variable that automatically increments or decrements as you iterate through the loop. Because youre using a counter, youll always loop from some start value to some end value. By default, a For...Next loop always increments by one every time through the loop. The value used to stop the loop can be a hard-coded number or a variable. See Figure 8.3 for an example of a For...Next loop.